package com.lixinkeji.base

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.viewbinding.ViewBinding
import com.drake.statusbar.immersive

abstract class BaseFragment<T : ViewBinding> : Fragment() {
    abstract fun getViewBinding(inflater: LayoutInflater,
                                container: ViewGroup?): T
    protected lateinit  var binding: T

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        Log.e("进入页面", this.javaClass.name)
//        val cls =
//            (javaClass.genericSuperclass as ParameterizedType).actualTypeArguments[0] as Class<T>
//        binding = cls.getMethod("inflate", LayoutInflater::class.java)
//            .invoke(null, inflater) as T
        binding=getViewBinding(inflater, container)
        return binding.root
    }

    open fun immersive(boolean: Boolean) {
        requireActivity().immersive(darkMode = boolean)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        iniView()
        onData()
        onClick()
    }

    abstract fun iniView()

    //数据填充
    open fun onData() {}

    //点击事件
    open fun onClick() {}


    //返回按钮监听
    open fun onBlackListener() {
        requireActivity().finish()
    }

    //右边文本监听
    open fun onTextMenuListener() {}

    //右边图片监听
    open fun onImageMenuListener() {}






}